#version 450 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
in vec3 tes_position[3];
in vec3 tes_patch_distance[3];
out vec3 facet_normal;
out vec3 patch_distance;
out vec3 tri_distance;
layout (location = 2) uniform mat4 model;
layout (location = 3) uniform mat4 view;
void main(void)
{
   mat3 normal_mat = mat3(transpose(inverse(view * model)));
   vec3 A = tes_position[2] - tes_position[0];
   vec3 B = tes_position[1] - tes_position[0];
   facet_normal = normal_mat * normalize(cross(A, B));
   patch_distance = tes_patch_distance[0];
   tri_distance  = vec3(1, 0, 0);
   gl_Position = gl_in[0].gl_Position;
   EmitVertex();
   patch_distance = tes_patch_distance[1];
   tri_distance  = vec3(0, 1, 0);
   gl_Position = gl_in[1].gl_Position;
   EmitVertex();
   patch_distance = tes_patch_distance[2];
   tri_distance  = vec3(0, 0, 1);
   gl_Position = gl_in[2].gl_Position;
   EmitVertex();
   EndPrimitive();
}
